<template>
	<view class="AllShop">
		<u-search placeholder="请输入输入店铺名" v-model="keyword" :showAction="false" @change="changeList()"></u-search>
		<scroll-view scroll-y="true" style="height: 100%;margin-top: 2%;flex: 1;height: 1px;">
			<view class="scrBox" v-for="(item,index) in searchList" :key="index" @click="goShopDetail(item.Id)">
				<view class="left">
					<image v-if="item.ShopLogo!=null" :src="item.ShopLogo" mode="aspectFit"></image>
					<!-- <image v-else src="../../static/images/shopCheck.png" mode="aspectFit"></image> -->
				</view>
				<view class="right">
					<view class="name">
						{{item.ShopName}}
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getShopBgList
	} from '@/api/mall.js';
	export default {
		data() {
			return {
				shopList: [], //实际数据
				keyword: '',
				searchList: [], //搜索的数据
			}
		},
		methods: {
			// 获取商家列表数据
			async getShopBgList() {
				uni.showLoading({});
				let WhereParam = [{
					Name: 'IsBusiness',
					Type: 'EqualTo',
					Value: 1,
				}]
				try {
					const {
						Data
					} = await getShopBgList({
						AreaId: 0,
						ShopName: '',
						SpotGrade: 0,
						HotelStars: 0,
						Size: 1000,
						WhereList: WhereParam
					})
					let arr = [];
					Data.forEach(con => {
						if (con.IsBusiness == 1) {
							arr.push(con)
						}
					})
					uni.hideLoading();
					this.shopList = arr;
					this.searchList = arr;
					console.log('获取商家列表数据', Data)
				} catch {

				}
			},
			goShopDetail(id) {
				uni.navigateTo({
					url: '/mall_subpages/shop/shopIndex?id=' + id
				})
			},
			//实时搜索当前数据
			changeList() {
				let that = this;
				let arr = [];
				that.shopList.forEach(con => {
					if (con.ShopName.indexOf(that.keyword) != '-1') {
						arr.push(con)
					}
				})
				that.searchList = arr;
			},
		},
		onLoad() {
			this.getShopBgList();
		},
	}
</script>

<style lang="scss" scoped>
	.AllShop {
		width: 100%;
		padding: 4%;
		display: flex;
		flex-direction: column;
		height: 100vh;

		.scrBox {
			display: flex;
			align-items: center;
			margin-bottom: 2%;

			.left {
				width: 25%;
				border-radius: 50%;
				box-shadow: 0 0 5px grey;

				image {
					width: 100%;
					height: 160rpx;
					border-radius: 50%;
				}
			}

			.right {
				margin-left: 4%;

				.name {
					font-size: 24rpx;
				}
			}
		}
	}

	/deep/ .u-search {
		flex: none !important;
	}
</style>